﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;


namespace Common.IO.FileIO
{
    public class ExcelIO
    {
        private string m_strExcelFilePath;
        public ExcelIO(string excelfilepath)
        {
            this.m_strExcelFilePath = excelfilepath;
        }

        public DataSet GetData()
        {
            string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                        "Extended Properties=Excel 8.0;" +
                        "data source= " + this.m_strExcelFilePath;

            string sql = "SELECT * FROM [Sheet1$]";

            DataSet ds = new DataSet();
            OleDbDataAdapter da = new OleDbDataAdapter(sql, connStr);
            da.Fill(ds);
            return ds;
        }

        public DataSet GetData(string sheetname)
        {
            string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                        "Extended Properties=Excel 8.0;" +
                        "data source= " + this.m_strExcelFilePath;

            string sql = "SELECT * FROM ["+ sheetname +"]";

            DataSet ds = new DataSet();
            OleDbDataAdapter da = new OleDbDataAdapter(sql, connStr);
            da.Fill(ds);
            return ds;
        }



    }
}
